package P1线性结构.LeetCode双指针;

public class LeetCode206 {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode pre = null;
        ListNode cur = head;
        ListNode next = null;
        while (cur != null) {
            next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }
    /*
        if (head == null || head.next == null) {
            return head;
        }
        ListNode dummyHead = new ListNode();
        ListNode p = head;
        while (p != null) {
            head = head.next;
            p.next = dummyHead.next;
            dummyHead.next = p;
            p = head;
        }
        return dummyHead.next;
    */
}
